<template>
  <div></div>
</template>

<script lang="ts">
  import { defineComponent } from "vue";
  import { useRoute } from "vue-router";
  import { useUserStore } from "/@/store/modules/user";
  import axios from "axios";
  import { useGlobSetting } from "/@/hooks/setting";

  export default defineComponent({
    name: "Login",
    setup() {
      const route = useRoute();
      const queryParams = route.query;
      const { token } = queryParams;
      const userStore = useUserStore();
      if (token) {
        //query参数中有token
        userStore.setToken(token as string);
        userStore.afterLoginAction(true);
      } else {
        //若没有token参数，向后端发送/login请求
        axios
          .get("/login", {
            baseURL: useGlobSetting().apiUrl,
            headers: {
              "x-requested-with": "XMLHttpRequest",
            },
          })
          .catch(({ response }) => {
            if (response.status === 401) {
              window.location.href = response.data;
            }
          });
        // loginApi().catch((response) => {
        //   window.location.href = response.data;
        // });
      }
      return {};
    },
  });
</script>

<style scoped></style>
